<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  var arr = function (head) {
    if (head === null || head.next === null) {//终止条件，必须要有两个节点
      return head;
    }
    const newHead = head.next;//反转后链表的头节点，
    head.next = arr(newHead.next);//让当前递归层的head.next指向交换后返回的头节点
    newHead.next = head;//让反转后的新的头节点指向当前层的head的节点
    return newHead;//返回反转后的头节点
  };
  console.log(arr(head = [1, 2, 3, 4]));
</script>

</html>